import CryptoJS from 'crypto-js/crypto-js'

        // 默认的 秘钥KEY 与 iv 
        const KEY = CryptoJS.enc.Utf8.parse("123456781234567F");  //  必須十六位十六进制数作为密钥 配合后端一起改
        const IV = CryptoJS.enc.Utf8.parse('12345678ABCDEF01');  //十六位十六进制数作为密钥偏移量
        /**
         * AES加密   CBC模式
         */
        export function Encrypt(word, keyStr, ivStr) {
          let key = KEY
          let iv = IV

          if (keyStr) {
            key = CryptoJS.enc.Utf8.parse(keyStr);
            iv = CryptoJS.enc.Utf8.parse(ivStr);
          }

          // 传过来的密码
          var encrypted = CryptoJS.AES.encrypt(word, key, {
            iv: iv,
            mode: CryptoJS.mode.CBC,
            padding: CryptoJS.pad.Pkcs7
          });
         // console.log("-=-=-=-", encrypted.ciphertext)
          return encrypted.toString()

        }
        /**
         * AES 解密 
         *
         */
        export function Decrypt(word, keyStr, ivStr) {
          let key  = KEY
          let iv = IV

          if (keyStr) {
            key = CryptoJS.enc.Utf8.parse(keyStr);
            iv = CryptoJS.enc.Utf8.parse(ivStr);
          }

          
          let decrypt = CryptoJS.AES.decrypt(word, key, {
              iv: iv,
              mode: CryptoJS.mode.CBC,
              padding: CryptoJS.pad.Pkcs7
          })
          let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8)
          return decryptedStr.toString()

        }